<template>
  <el-dialog
    title="缺陷记录"
    v-if="showFlag"
    :visible.sync="showFlag"
    :modal="false"
    width="80%"
    center
  >
    <el-table v-loading="loading" :data="defectrecordList">
      <el-table-column
        label="缺陷描述"
        width="400px"
        align="center"
        prop="defectName"
      >
      </el-table-column>
      <el-table-column label="缺陷等级" align="center" prop="defectLevel">
        <template slot-scope="scope">
          <el-select v-model="scope.row.defectLevel">
            <el-option
              v-for="dict in dict.type.mes_defect_level"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            />
          </el-select>
        </template>
      </el-table-column>
      <el-table-column label="缺陷数量" align="center" prop="defectQuantity"/>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
    <div slot="footer" class="dialog-footer">
      <el-button @click="showFlag = false">关 闭</el-button>
    </div>
  </el-dialog>
</template>

<script>
import { listDefectrecord } from "@/api/mes/qc/defectrecord";

export default {
  name: "DefectrecordSelect",
  dicts: ["mes_defect_level"],
  props: {
    qcId: null,
    qcType: null,
    lineId: null,
    optType: null,
  },
  watch: {
    qcId() {
      this.queryParams.qcId = this.qcId;
    },
    qcType() {
      this.queryParams.qcType = this.qcType;
    },
    lineId() {
      this.queryParams.lineId = this.lineId;
    },
  },
  data() {
    return {
      showFlag: false,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 检验单缺陷记录表格数据
      defectrecordList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        qcType: this.qcType,
        qcId: this.qcId,
        lineId: this.lineId,
        defectName: null,
        defectLevel: null,
        defectQuantity: null,
      },
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询检验单缺陷记录列表 */
    getList() {
      this.loading = true;
      listDefectrecord(this.queryParams).then((response) => {
        this.defectrecordList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
  },
};
</script>
